package me.chan.sort;

import static me.chan.util.SortUtil.*;

/**
 * Created by JanGin on 2017/9/18.
 */
public class BubbleSortWithExchFlag {

    public static void sort(Comparable[] a) {

        boolean isSort = false;
        for (int i=0; i < a.length - 1 && !isSort; i++) {
            isSort = true;
            for (int j = 0; j < a.length - 1 - i ; j++) {
                if (less(a[j+1], a[j])) {
                    exch(a, j, j+1);
                    isSort = false;
                }

            }
            //System.out.println("第"+(i+1)+"轮排序结果:");
            //show(a);

        }
    }

    public static void main(String[] args) {
        Integer[] arr = { 20, 17, 12, 9, 10, 23, 13, 24, 19, 93, 8, 15, 68, 93, 98 };
        show(arr);
        sort(arr);
    }
}
